/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mattespill.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import mattespill.*;

/**
 *
 * @author Erik
 */
public class GUIGetStatus extends JPanel {

    private Oversikt oversikt;
    private JTable tabell;
    private JButton tilbake = new JButton("Tilbake");
    private final String [] kolonneNavn = {"Elev-ID","Elevnavn","Krokodillespillet","Kyllingtetris","Penger","Poeng"};

    public GUIGetStatus(Oversikt o) {
        this.oversikt = o;

        DefaultTableModel model = new DefaultTableModel();
        tabell = new JTable(null,kolonneNavn);
        JScrollPane scrollPane = new JScrollPane(tabell);
        
        scrollPane.setBackground(new Color(255,255,255,150));
        this.setBackground(new Color(255,255,255,150));
        scrollPane.getViewport().setOpaque(false);
        tabell.setModel(model);
        model.setColumnIdentifiers(new String [] {"Elev-ID","Elevnavn","Krokodillespillet","Kyllingtetris","Penger","Poeng"});
        for(BrukerStatus b : oversikt.getBrukerStatus(oversikt.getBruker().getBruker_id())){
            model.addRow(new String[] {""+b.getBruker().getBruker_id(), b.getBruker().getNavn(), ""+b.getStatus().getSpill1(),""+b.getStatus().getSpill2(),""+b.getStatus().getPenger(),""+b.getStatus().getPoeng()});
        }
        setLayout(new BorderLayout());
        add(scrollPane,BorderLayout.CENTER);

        tilbake.addActionListener(new Knapplytter());
        add(new Panelet(),BorderLayout.SOUTH);
    }
    private class Panelet extends JPanel {
        public Panelet() {
            setBackground(new Color(255,255,255,150));
            add(tilbake);
        }
    }
    private class Knapplytter implements ActionListener{

        public void actionPerformed(ActionEvent e) {
            JButton hendelse = (JButton)e.getSource();
            if(hendelse.equals(tilbake)){
                GUIAdminpanel g = new GUIAdminpanel(oversikt);
                JPanel mainPanel = (JPanel)getParent();
                mainPanel.removeAll();// dette is the sub-panel
                mainPanel.repaint();
                mainPanel.add(g);
                mainPanel.revalidate();
                g.repaint();
            }
        }

    }
}


